﻿using System.Diagnostics;
using LFSRecord2.Misc;

namespace LFSRecord2.Model.UserActions
{
    public class UserActionKeyFrameEaseChanged : UserActionBase
    {
        // Action description, so we can replay this action (and reverse it)
        public int LayerIndex { get; set; }
        public int PropertyIndex { get; set; }
        public int KeyFrameIndex { get; set; }
        public double OldEaseIn { get; set; }
        public double NewEaseIn { get; set; }
        public double OldEaseOut { get; set; }
        public double NewEaseOut { get; set; }

        public UserActionKeyFrameEaseChanged()
        {
            Action = UserActionTypes.KeyFrameEaseChanged;
        }

        public override void DoUndo()
        {
            Debug.WriteLine("Undoing a KeyFrameEaseChanged action");
            if (KeyFrameIndex > LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames.Count - 1)
            {
                Logger.LogError("Invalid keyframe reference while undoing kfEaseAction");
            }
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].EaseInValue = OldEaseIn;
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].EaseOutValue = OldEaseOut;
        }

        public override void DoRedo()
        {
            Debug.WriteLine("Redoing a KeyFrameEaseChanged action");
            if (KeyFrameIndex > LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames.Count - 1)
            {
                Logger.LogError("Invalid keyframe reference while redoing kfEaseAction");
            }
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].EaseInValue = NewEaseIn;
            LfsRecordController.project.Layers[LayerIndex].Properties[PropertyIndex].KeyFrames[KeyFrameIndex].EaseOutValue = NewEaseOut;
        }
    }
}
